package org.jeecg.modules.manager.mapper.provider;

import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.manager.entity.StockQueryVo;

/**
 * @author wenhao hu
 * @title: StockProvider
 * @projectName biyesheji
 * @description: TODO
 * @date 2021/12/511:19
 */
public class StockProvider {

    public String page(StockQueryVo vo){
        StringBuilder buffer = new StringBuilder("select\n" +
                "s.id,concat('品牌:',base_car.car_brand,' 车系:',base_car.car_name,' 生产商:',base_car_info.info_manufacturer,' 版本型号:',base_car_info.info_version,' 颜色:',base_car_info.info_color) as goodsName,base_spare_parts.spare_parts_name as goodsName2,\n" +
                "       base_repo.repo_name,s.stock_count as count,base_repo.repo_address\n" +
                "from stock s\n" +
                "left join base_car_info on info_id = s.stock_goods_id\n" +
                "left join base_car on car_id = base_car_info.parent_id\n" +
                "left join base_repo on base_repo.repo_id = s.stock_repo_id\n" +
                "left join base_spare_parts on base_spare_parts.spare_parts_id = s.stock_goods_id\n" +
                "where 1=1");
        if (StringUtils.isNotBlank(vo.getRepoName())){
            buffer.append("and base_repo.repo_name like '%").append(vo.getRepoName()).append("%'");
        }
        if (StringUtils.isNotBlank(vo.getRepoAddress())){
            buffer.append("and base_repo.repo_address like '%").append(vo.getRepoAddress()).append("%'");
        }
        if (StringUtils.isNotBlank(vo.getGoodsName())) {
            buffer.append("having goodsName like '%").append(vo.getGoodsName()).append("%'").append(" or ").append("goodsName2 like '%").append(vo.getGoodsName()).append("%'");
        }

        return buffer.toString();
    }
}
